<template>
	<view>
		<u-datetime-picker :show="show" v-model="value1" mode="date" @confirm="confirm" @cancel="show=false">
		</u-datetime-picker>
		<view class="mainpadding ffffff margin_top">
			<view class="inputbox margin_top">
				<view class="flexleft flex1">
					<view class="strongtext margin_right shangbianju">商品名称</view>
				</view>
				<view class="itembox flexbetween">
					<input type="text" class="inputs" placeholder="请输入商品名称" disabled=""
						v-model="dataAll.goodsinfo.name">
				</view>
			</view>
			<view class="inputbox margin_top" v-if="dataAll.goodsinfo.producedate_status==1">
				<view class="flexleft flex1">
					<view class="strongtext margin_right shangbianju">生产日期</view>
				</view>
				<view class="itembox flexbetween" @click="show=true">
					<input type="text" class="inputs" placeholder="选择生产日期" disabled="true"
						v-model="dataAll.produce_time">
					<uni-icons type="arrow-right" size="20" color="#999999"></uni-icons>
				</view>
				
			</view>
			<view class="inputbox margin_top">
				<view class="flexleft flex1">
					<view class="strongtext margin_right shangbianju">单价</view>
				</view>
				<view class="itembox">
					<input type="number" class="inputs" placeholder="请输入单价" v-model="dataAll.price">
				</view>
			</view>
			<view class="inputbox margin_top">
				<view class="flexleft flex1">
					<view class="strongtext margin_right shangbianju">数量</view>
				</view>
				<view class="itembox">
					<input type="number" class="inputs" placeholder="请输入数量" v-model="dataAll.num">
				</view>
			</view>
			<view class="inputbox margin_top">
				<view class="flexleft flex1">
					<view class="strongtext margin_right shangbianju">金额</view>
				</view>
				<view class="itembox">
					<input type="number" class="inputs" placeholder="请输入金额" disabled=""
						:value="dataAll.num*dataAll.price">
				</view>
			</view>
			<view class="inputbox margin_top">
				<view class="flexleft flex1">
					<view class="strongtext margin_right shangbianju">备注</view>
				</view>
				<view class="itembox">
					<input type="text" class="inputs" placeholder="请输入备注" v-model="dataAll.notes">
				</view>
			</view>
			<view class="inputbox margin_top">
				<view class="flexleft flex1">
					<view class="strongtext margin_right shangbianju">赠品数量</view>
				</view>
				<view class="itembox">
					<input type="number" class="inputs" placeholder="请输入数量" v-model="dataAll.send_num">
				</view>
			</view>
			<view class="inputbox margin_top">
				<view class="flexleft flex1">
					<view class="strongtext margin_right shangbianju">赠送备注</view>
				</view>
				<view class="itembox">
					<input type="number" class="inputs" placeholder="请输入赠送备注" v-model="dataAll.send_notes">
				</view>
			</view>
		</view>
		<view class="mainpadding_top">
			<view class="flexcenter xiaohui" @click="qingkong">删除</view>
			<view class="submitbtn margin_top" @click="submit">确认</view>
		</view>
		<u-picker :show="timePickershow" :columns="timePickercolumns" @confirm="timePickersure" title="选择生产日期"
			keyName="produce_time_text" @cancel="timePickershow=false"></u-picker>
	</view>
</template>

<script>
	const httpRequest = require("@/commonFun/httpRequest.js")
	export default {
		data() {
			return {
				// 日期选择
				show: false,
				value1: Number(new Date()),
				timePickershow: false,
				timePickercolumns: [],
				type: 1, //1采购单,2采购退货单,3销售单
				dataAll: {},
				index: "", //当前编辑数据的下标
			}
		},
		// 采购单生产日期（自定义选择）
		onLoad(options) {
			let data = JSON.parse(decodeURIComponent(options.msg));
			this.type = data.type
			this.dataAll = data.item
			this.index = data.index
		},
		methods: {
			submit() {
				let tuihuodanInfo = JSON.parse(uni.getStorageSync("tuihuodanInfo"))
				tuihuodanInfo.data.splice(this.index, 1, this.dataAll)
				uni.setStorageSync('tuihuodanInfo', JSON.stringify(tuihuodanInfo))
				httpRequest.toast("修改成功");
				setTimeout(function() {
					uni.navigateBack({
						delta: 1
					})
				}, 500)
			},
			// 删除当前商品
			delet() {
				if (this.type == 4) { //退货单
					let tuihuodanInfo = JSON.parse(uni.getStorageSync("tuihuodanInfo"))
					tuihuodanInfo.data.splice(this.index, 1)
					uni.setStorageSync('tuihuodanInfo', JSON.stringify(tuihuodanInfo))
					httpRequest.toast("删除成功");
					setTimeout(function() {
						uni.navigateBack({
							delta: 1
						})
					}, 500)
				}
			},
			timePickersure(e) {
				this.dataAll.produce_time = e.value[0].produce_time_text
				this.timePickershow = false
			},
			// 选择生产日期
			confirm(e) {
				this.dataAll.produce_time = httpRequest.returnDate(e.value);
				this.show = false;
			},
		}
	}
</script>
<style lang="scss" scoped>
	.inputs {
		font-size: 28rpx;
	}

	.huisetext {
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #666666;
	}

	//
	.flex1 {
		flex: 3;
	}

	.inputbox {
		display: flex;
		align-items: flex-start;
		justify-content: space-between;
	}

	.itembox {
		flex: 7;
		width: 100%;
		padding-bottom: 20rpx;
		border-bottom: 1rpx solid rgba(153, 153, 153, 0.06);
	}

	.lansetext {
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #0BBDCB;
	}

	.shangbianju {
		margin-top: 10rpx;
	}
</style>